<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/include/header.jsp"%>
<!-- 加载树-->
<script src="${ctx}/js/component/tree.js" type="text/javascript"></script>
<!-- 加载树-->
<%@ include file="/include/zTree.jsp"%>
</head>
<body>
	<div class="main_panel">
		<div class="ch_panel" id="queryDiv">
			<input type="hidden" data-qname="CSRFToken" id="CSRFToken" value="${csrfToken}" id="csrfToken" />
			<input type="hidden" data-qname="deleteFlag" id="deleteFlag" value="-1" />
			<input type="hidden" data-qname="currentPage" value="1" />
			<table class="c_table">
				<tr>
					<td>
						<button class="a_btn" id="addBtn">新增</button>
					</td>
					<td class="t_l">
						用户名：
						<input type="text" data-qname="username" id="username" value="" class="input_txt" style="width: 180px" />
						&nbsp;&nbsp; 状态 ： <select id="status" data-qname="status" style="width: 180px;" class="input_txt">
							<option value="">--请选择--</option>
							<c:forEach items="${statusMap}" var="var">
								<option value="${var.key }">${var.value}</option>
							</c:forEach>
						</select>&nbsp;&nbsp;
					</td>
					<td class="t_r">
						<input type="button" value="查询" id="searchBtn" class="c_btn" />
					</td>
				</tr>
			</table>
		</div>
		<table id="tbwrap" class="table table-border table-bordered table-bg m_t10 hovaertable"></table>
		<div class="page eui-pager-custom" id="j_pager"></div>
	</div>
	<div id="menuContent" class="menuContent">
		<ul id="treeDemo" class="ztree" style="margin-top: 0; width: 300px; z-index: 10"></ul>
	</div>
	
	<%@ include file="/include/footer.jsp"%>
	<script type="text/html" id="tb_template">
	    <thead>
			<tr>
				<th>用户名</th>
				<th>用户中文名称</th>
				<th>状态</th>
				<th>拥有角色</th>
				<th>所属部门</th>
				<th width="20%">操作</th>
			</tr>
		</thead>
		<tbody data-type="body" id="queryTable">
    		<!if(list.length>0) { !>
        		<!for(var i=0,len=list.length;i<len;i++){
            		var item = list[i],classItem = (i%2!=0)?"odd td_odd":"even";
          		!>
		    	<tr class="gradeA <!=classItem!>">
			    	<td><!=item["username"]!></td>
					<td><!=item["userCnName"]!></td>
					<td><!=item["statusName"]!></td>
					<td><a data-value="<!=item["userId"]!>" class="aboutRole">查看</a></td>
					<td><a data-value="<!=item["userId"]!>" class="aboutDept">查看</a></td>
					<td>
						<a title="角色" data-value="<!=item["userId"]!>" class="setRole" style="text-decoration: none;margin-right: 10px;">设置角色</a> 

						<a title="详情" data-value="<!=item["userId"]!>" class="view" style="text-decoration: none;margin-right: 10px;">
							<i class="Hui-iconfont">&#xe665;</i>
						</a>
						<a title="编辑" data-value="<!=item["userId"]!>" class="edit" style="text-decoration: none;margin-right: 10px;">
							<i class="Hui-iconfont">&#xe6df;</i>
						</a>
						<a title="删除" data-value="<!=item["userId"]!>" class="delete" style="text-decoration: none">
							<i class="Hui-iconfont">&#xe6e2;</i>
						</a>
					</td>
		   		</tr>
        	<!}!>
    		<!}else{!>
				<tr>
		    		<td colspan="5"> 暂无数据</td>
				</tr>
    		<!}!>
 		</tbody>
	</script>

	<script type="text/javascript">
		$(function(){
			
			// 添加
			$("#addBtn").click(function() {
				parent.member_add("添加系统用户信息", "${ctx}/sysUser/toAdd",800,460);
			});
			
			// 编辑
			$("#tbwrap").delegate(".edit", "click", function() {
				//获取主键
				var userId = $(this).data("value");
				parent.member_add("编辑系统用户信息", "${ctx}/sysUser/toEdit?userId="+userId,800,460);
				
			});
			
			// 详细
			$("#tbwrap").delegate(".view", "click", function() {
				//获取主键
				var userId = $(this).data("value");
				parent.member_add("查看系统用户信息", "${ctx}/sysUser/view?userId="+userId,600,300);
				
			});
			
			// 4、删除
			$("#tbwrap").delegate(".delete", "click", function () {
				var userId = $(this).data("value");
				var csrfToken=$("#CSRFToken").val();
				if (confirm('确定删除？')) {
					$.post("${ctx}/sysUser/delete", {userId:userId,CSRFToken:csrfToken}, function (result) {
			            if ("succ" == result) {
			            	alert("操作成功");
							// 刷新列表页面
							search();
			            }else {
			            	alert(result);
			            }
			        }, "json");
				}
				
			});
			
			// 5、设置角色
			$("#tbwrap").delegate(".setRole", "click", function() {
				//获取主键
				var userId = $(this).data("value");
				parent.member_add("设置角色", "${ctx}/sysUser/toSetRole?userId="+userId,850,550);
				
			});
			
			// 6、弹出关联角色
			$("#tbwrap").delegate(".aboutRole", "click", function() {
				//获取主键
				var userId = $(this).data("value");
				parent.member_add("拥有角色", "${ctx}/sysUser/relevanceRole?userId="+userId,600,290);
				
			});
			
			// 7、弹出关联部门
			$("#tbwrap").delegate(".aboutDept", "click", function() {
				//获取主键
				var userId = $(this).data("value");
				parent.member_add("拥有角色", "${ctx}/sysUser/relevanceDept?userId="+userId,600,290);
				
			});

			// 5、查询
			$("#searchBtn").click(function () {
				search();
	        });
		});
		
	</script>

	<script type="text/javascript">
		$(function () {
	        search();
	    });
		
		function changeValue(value){
			if(value=="1"){
				$("#searchFlagYes").attr("checked", true);
				$("#searchFlagNo").attr("checked", false);
			}else{
				$("#searchFlagYes").attr("checked", false);
				$("#searchFlagNo").attr("checked", true);
			}
			$("#searchFlag").val(value);
		}
		
		function search() {
			// 这里放包含查询条件的DIV
			var paramData = easyUtils.getQueryDivDefault("queryDiv");
			seajs.use([ "component/table" ], function(uiTable) {
				var param = {
					url : "${ctx}/sysUser/ajaxPage",
					data : paramData
				};
				easyUtils.getData(param, function(result) {
					easyUtils.buildTable(result, param, uiTable);
				});
			});
		}
		
	</script>
</body>
</html>